package cyou.breathe.blog.email.config;

import cyou.breathe.blog.email.EmailService;
import cyou.breathe.blog.email.EmailServiceImpl;
import cyou.breathe.blog.email.MockEmailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * @author: breathe
 * @createTime: 2025-08-26
 */
@Configuration
@EnableConfigurationProperties(EmailProperties.class)
public class EmailConfiguration {
    @Autowired
    private EmailProperties properties;
    @Bean
    @ConditionalOnMissingBean
    @Profile({"default","prod"})
    public EmailService emailService() {
        EmailServiceImpl emailService = new EmailServiceImpl();
        emailService.setUser(properties.getUser());
        emailService.setCode(properties.getCode());
        emailService.setHost(properties.getHost());
        emailService.setAuth(properties.isAuth());
        emailService.setPort(properties.getPort());
        emailService.setSmtpSslEnable(properties.isSmtpSslEnable());
        return emailService;
    }

    @Bean
    @ConditionalOnMissingBean
    @Profile({"dev","test"})
    public EmailService mockEmailService() {
        return new MockEmailServiceImpl();
    }
}